<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
	<head>
		<title>
			efbu.c
			</title>
		<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
		<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
		<meta name='author' content='cmaier@cmassoc.net'/>
		<meta name='robots' content='noindex,nofollow'/>
		<link href='toolkit.css' rel='stylesheet' type='text/css'/>
		</head>
	<body>
		<div class='headerlink'>
			[<a href='edsu.c.html' title=' edsu.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='efeu.c.html' title=' efeu.c '>NEXT</a>]
			</div>
<pre>
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or 
 *   without modification, are permitted (subject to the limitations 
 *   in the disclaimer below) provided that the following conditions 
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials 
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of 
 *     its contributors may be used to endorse or promote products 
 *     derived from this software without specific prior written 
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE 
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR 
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   efbu.c - Ethernet Frame Blast Utility;
 *
 *   transmit an IP broadcast frame of maximum length at maximum rate
 *   for a given period of time in seconds;
 *
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *   system header files;
 *--------------------------------------------------------------------*/

#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;limits.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/time.h&gt;

/*====================================================================*
 *   custom header files;
 *--------------------------------------------------------------------*/

#include &quot;../tools/getoptv.h&quot;
#include &quot;../tools/putoptv.h&quot;
#include &quot;../tools/error.h&quot;
#include &quot;../tools/memory.h&quot;
#include &quot;../tools/number.h&quot;
#include &quot;../tools/symbol.h&quot;
#include &quot;../tools/flags.h&quot;
#include &quot;../ether/channel.h&quot;

/*====================================================================*
 *   custom source files;
 *--------------------------------------------------------------------*/

#ifndef MAKEFILE
#include &quot;../tools/getoptv.c&quot;
#include &quot;../tools/putoptv.c&quot;
#include &quot;../tools/version.c&quot;
#include &quot;../tools/error.c&quot;
#include &quot;../tools/basespec.c&quot;
#include &quot;../tools/uintspec.c&quot;
#include &quot;../tools/hexencode.c&quot;
#include &quot;../tools/hexdump.c&quot;
#include &quot;../tools/todigit.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../ether/openchannel.c&quot;
#include &quot;../ether/closechannel.c&quot;
#include &quot;../ether/readpacket.c&quot;
#include &quot;../ether/sendpacket.c&quot;
#include &quot;../ether/channel.c&quot;
#endif

/*====================================================================*
 *   program contants;
 *--------------------------------------------------------------------*/

#define EFBU_VLAN_TAG 0
#define EFBU_INTERFACE &quot;PLC&quot;
#define EFBU_ETHERTYPE ETH_P_802_2
#define EFBU_BINARY 0xAA
#define EFBU_TIMER 1000
#define EFBU_PAUSE 50

#ifndef ETHER_CRC_LEN
#define ETHER_CRC_LEN 4
#endif

#if defined (WIN32)
#define SLEEP(milliseconds) Sleep(milliseconds)
#else
#define SLEEP(milliseconds) usleep(1000*(milliseconds))
#endif

/*====================================================================*
 *
 *   void function (struct channel * channel, void * memory, unsigned extent, unsigned timer, unsigned pause);
 *
 *   transmit an IP broadcast frame of given length at maximum rate
 *   for a given period of time in seconds;
 *
 *
 *--------------------------------------------------------------------*/

static void function (struct channel * channel, void * memory, ssize_t extent, byte binary, unsigned timer, unsigned pause)

{

#if EFBU_VLAN_TAG

	struct ether_header
	{
		uint8_t ether_dhost [ETH_ALEN];
		uint8_t ether_shost [ETH_ALEN];
		uint32_t ether_vlan;
		uint16_t ether_type;
	}
	__attribute__ ((__packed__)) * frame = (struct ether_header *)(memory);

#else

	struct ether_header * frame = (struct ether_header *)(memory);

#endif

	struct timeval ts;
	struct timeval tc;
	unsigned since;
	memset (memory, binary, extent);
	if (extent &gt; (ETHER_MAX_LEN - ETHER_CRC_LEN))
	{
		extent = ETHER_MAX_LEN - ETHER_CRC_LEN;
	}
	memcpy (frame-&gt;ether_dhost, channel-&gt;peer, sizeof (frame-&gt;ether_dhost));
	memcpy (frame-&gt;ether_shost, channel-&gt;host, sizeof (frame-&gt;ether_shost));

#if EFBU_VLAN_TAG

	frame-&gt;ether_vlan = htonl (0x8100A000);

#endif

	frame-&gt;ether_type = htons (channel-&gt;type);
	if (gettimeofday (&amp;ts, NULL) == -1)
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (since = 0; since &lt; timer; since = (tc.tv_sec - ts.tv_sec) * 1000 + ((tc.tv_usec - ts.tv_usec) / 1000))
	{
		sendpacket (channel, memory, extent);
		if (gettimeofday (&amp;tc, NULL) == -1)
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		SLEEP (pause);
	}
	return;
}

/*====================================================================*
 *
 *   int main (int argc, char const * argv []);
 *
 *
 *
 *--------------------------------------------------------------------*/

int main (int argc, char const * argv [])

{
	extern struct channel channel;
	static char const * optv [] =
	{
		&quot;b:d:e:hi:p:t:v&quot;,
		&quot;&quot;,
		&quot;Ethernet Frame Blast Utility&quot;,
		&quot;b n\tbinary byte value is (n) [&quot; LITERAL (EFBU_BINARY) &quot;]&quot;,
		&quot;d x\treplace destination address with (x)&quot;,
		&quot;e x\tethertype is (x) [&quot; LITERAL (EFBU_ETHERTYPE) &quot;]&quot;,
		&quot;h\treplace source address with host address&quot;,

#if defined (WINPCAP) || defined (LIBPCAP)

		&quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,

#else

		&quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,

#endif

		&quot;t n\ttransmit for (n) milliseconds [&quot; LITERAL (EFBU_TIMER) &quot;]&quot;,
		&quot;p n\tpause (n) milliseconds between frames [&quot; LITERAL (EFBU_PAUSE) &quot;]&quot;,
		&quot;v\tverbose messages&quot;,
		(char const *) (0)
	};
	byte buffer [ETHER_MAX_LEN];
	byte binary = EFBU_BINARY;
	unsigned timer = EFBU_TIMER;
	unsigned pause = EFBU_PAUSE;
	signed c;
	if (getenv (EFBU_INTERFACE))
	{

#if defined (WINPCAP) || defined (LIBPCAP)

		channel.ifindex = atoi (getenv (EFBU_INTERFACE));

#else

		channel.ifname = strdup (getenv (EFBU_INTERFACE));

#endif

	}
	optind = 1;
	memset (channel.peer, 0xFF, sizeof (channel.peer));
	memset (channel.host, 0xFF, sizeof (channel.host));
	channel.type = EFBU_ETHERTYPE;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'b':
			binary = (uint8_t)(uintspec (optarg, 0, 255));
			break;
		case 'd':
			_setbits (channel.flags, CHANNEL_UPDATE_TARGET);
			if (!hexencode (channel.peer, sizeof (channel.peer), optarg))
			{
				error (1, errno, &quot;%s&quot;, optarg);
			}
			break;
		case 'e':
			channel.type = (uint16_t)(basespec (optarg, 16, sizeof (channel.type)));
			break;
		case 'h':
			_setbits (channel.flags, CHANNEL_UPDATE_SOURCE);
			break;
		case 'i':

#if defined (WINPCAP) || defined (LIBPCAP)

			channel.ifindex = atoi (optarg);

#else

			channel.ifname = optarg;

#endif

			break;
		case 'p':
			pause = (unsigned)(uintspec (optarg, 0, UINT_MAX));
			break;
		case 'q':
			_setbits (channel.flags, CHANNEL_SILENCE);
			break;
		case 't':
			timer = (unsigned)(uintspec (optarg, 0, UINT_MAX));
			break;
		case 'v':
			_setbits (channel.flags, CHANNEL_VERBOSE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc)
	{
		error (1, ECANCELED, ERROR_TOOMANY);
	}
	openchannel (&amp;channel);
	function (&amp;channel, buffer, sizeof (buffer), binary, timer, pause);
	closechannel (&amp;channel);
	return (0);
}


</pre>
		<div class='footerlink'>
			[<a href='edsu.c.html' title=' edsu.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='efeu.c.html' title=' efeu.c '>NEXT</a>]
			</div>
		</body>
	</html>
